﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Zero.Model;
using Zero.Code;

namespace Zero.DAL
{
    /// <summary>
    ///用户登录数据层
    ///作者：edl
    ///最后修改日期：2019-9-21
    /// </summary>
    public class UserLogInfo
    {
        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="username">账户</param>
        /// <param name="password">密码</param>
        /// <returns></returns>
        public string CheckLogin(string username, string password)
        {

            using (var db= new zerodbEntities())
            {
                var User = from l in db.userloginfo
                           where l.L_Account == username && l.L_UserPassWord == password
                           select l;
                var item = User.FirstOrDefault();
                if(User.Count()==1)
                    return new AjaxResult { state = ResultType.success.ToString(), message = "登录成功" ,data=item,}.ToJson();
                else
                    return new AjaxResult { state = ResultType.error.ToString(), message = "账户名或密码错误！" }.ToJson();
            }
            
        }

        /// <summary>
        /// 获取用户信息
        /// </summary>
        /// <param name="UserId">用户ID</param>
        /// <returns></returns>
        public users GetUserInfo(int UserId)
        {
            using (var db=new zerodbEntities())
            {
                var UserInfo = from u in db.users
                               where u.U_Id == UserId
                               select u;
                return UserInfo.FirstOrDefault();
            }
        }
    }
}
